/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 11:06:35 AM
 * To change this template use File | Settings | File Templates.
 */

import java.util.Iterator;
import java.util.List;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Boolexp, InternalSchemaErrorException, Schema, Context

class ImplyBoolexp extends Boolexp
{

    ImplyBoolexp(Element element, Schema schema)
    {
        Iterator iterator = element.getChildren().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element1 = (Element)iterator.next();
            if(!Schema.isDSDElement(element1))
                continue;
            exp1 = parse(element1, schema);
            break;
        } while(true);
        do
        {
            if(!iterator.hasNext())
                break;
            Element element2 = (Element)iterator.next();
            if(!Schema.isDSDElement(element2))
                continue;
            exp2 = parse(element2, schema);
            break;
        } while(true);
        if(exp2 == null)
            throw new InternalSchemaErrorException();
        else
            return;
    }

    byte evaluate(Context context)
    {
        byte byte0 = exp1.evaluate(context);
        byte byte1 = exp2.evaluate(context);
        if(byte0 == 2 || byte1 == 1)
            return 1;
        if(byte0 == 1 && byte1 == 2)
            return 2;
        return (byte) (byte0 != 4 && byte1 != 4 && (byte0 != 3 || byte0 != 3) ? 3 : 4);
    }

    boolean isMentioned(Context context)
    {
        return !exp1.isMentioned(context) || exp2.isMentioned(context);
    }

    Element toXML(Context context)
    {
        return (new Element("imply", "http://www.brics.dk/DSD/2.0")).addContent(exp1.toXML(context)).addContent(exp2.toXML(context));
    }

    boolean containsThis(Context context)
    {
        return exp1.containsThis(context) || exp2.containsThis(context);
    }

    Boolexp exp1;
    Boolexp exp2;
}
